#include <iostream>
using namespace std;

void overBan(int arr[], int n)
{
	int i = 0;
	int j = n-1;
	while(i <= j) {
		int temp = arr[i];
		arr[i] = arr[j];
		arr[j] = temp;
		i++;
		j--;
	}
}

int GetMaxI(int arr[], int n)
{
	int max = arr[0];
	int maxI = 0;
	for(int i = 0 ; i < n; i++) {
		if(max < arr[i]) {
			max = arr[i];
			maxI = i;
		}
	}
	return maxI;
}

int main()
{
	int n;
	cin >> n;
	int arr[1000];
	for(int i = 0; i < n; i++) 
	{
		cin >> arr[i];
	}

	int cnt = 0;
	while(n > 0) 
	{
		int maxI = GetMaxI(arr, n);


		if(maxI != n-1) 
		{
			cnt += (maxI == 0)?1:2;	
			overBan(arr, maxI + 1);
			overBan(arr, n);
		} 
		n--;

	}
	cout<< cnt << endl;
	return 0; 


}
